package acm.pta;

import java.util.*;

public class T92 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Set<Integer>[] set = new HashSet[n];
        for(int i = 0; i < n; i++) {
            int m = scanner.nextInt();
            set[i] = new HashSet<>();
            for(int j = 0; j < m; j++) {
                int tmp = scanner.nextInt();
                set[i].add(tmp);
            }
        }
        int k = scanner.nextInt();
        for(int i = 0; i < k; i++) {
            int x = scanner.nextInt() - 1;
            int y = scanner.nextInt() - 1;
            int nc = 0; //两个集合的相同个数
            for(int num : set[y]) {
                if(set[x].contains(num)) {
                    nc++;
                }
            }
            int nt = set[x].size() + set[y].size() - nc;
            double per = nc * 100.0 / nt;
            System.out.printf("%.2f%%", per);
            if(i != k - 1) {
                System.out.println();
            }
        }
        scanner.close();
    }

    static {
        int count=1000;
        Random random=new Random();
        while (count-- > 0) {
            Set<Integer> set1=new HashSet<>();
            Set<Integer> set2=new HashSet<>();
            int s1=random.nextInt(10000)+1;
            int s2=random.nextInt(10000)+1;
            while (set1.size() < s1) {
                set1.add(random.nextInt(2000000000));
            }
            while (set2.size() < s2) {
                set2.add(random.nextInt(2000000000));
            }
            long start=0,end=0;
            start=System.currentTimeMillis();
            test(set1,set2);
            end=System.currentTimeMillis();
            long time1=end-start;
            start=System.currentTimeMillis();
            compare(set1,set2);
            end=System.currentTimeMillis();
            long time2 = end - start;
            if (time2>time1+2){
                System.out.println("--------------------------------------------------------");
                System.out.println(set1.size());
                System.out.println(set2.size());
                System.out.println(time2-time1);
//                System.out.println(set1.size());
//                System.out.println(set2.size());
//                throw new RuntimeException("sss");
            }
        }
    }

    private static void test(Set<Integer> set1,Set<Integer> set2){
        int nc = 0; //两个集合的相同个数
        for(int num : set1) {
            if(set2.contains(num)) {
                nc++;
            }
        }
        int nt = set1.size() + set2.size() - nc;
        double per = nc * 100.0 / nt;
        System.out.printf("%.2f%%", per);
//        System.out.println();
    }

    public static void compare(Set<Integer> o1,Set<Integer> o2){
        double res=0;
        //n的复杂度
        for (Integer o : o1) {
            if (o2.contains(o)){
                res++;
            }
        }
//        //n+m的复杂度
//        Set<Integer> union=new HashSet<>();
//        union.addAll(o1);
//        union.addAll(o2);
//        res=o1.size()+o2.size()-union.size();
        double nt= o1.size()+o2.size()-res; //1的复杂度
        System.out.println(String.format("%.2f",res/nt*100)+"%");
    }
}
